/*!
 * \file Allocator.cpp
 * \brief Memory allocator module.
 * \author Nus
 * \date 2008/02/16, 13:21
 */

#include "Debug.h"
#include "Allocator.h"

// Default constructor.
Allocator::Allocator()
{
  mMemoryHandle.mem_chain = NULL;
  mMemoryHandle.last = NULL;
  mMemoryHandle.auto_tag = 0;
  mMemoryHandle.used_memory = 0;
}

// Default destructor.
Allocator::~Allocator()
{
#ifndef _NDEBUG
  dumpInfoEx();
#endif
  ASSERT_C(mMemoryHandle.mem_chain == NULL);
  ASSERT_C(mMemoryHandle.used_memory == 0);
}

// Allocate memory.
void* Allocator::memAlloc(size_t size, s32 align, const s8* file_loc,
                          s32 line_loc)
{
  return memAllocFromHandle(&mMemoryHandle, size, align, file_loc, line_loc);
}

// Deallocate memory.
void Allocator::memFree(void* addr)
{
  ::memFree(addr);
}

// Dump memory info.
void Allocator::dumpInfo(void) const
{
#ifndef _NDEBUG
  DumpInfo(&mMemoryHandle);
#endif
}

// Dump memory info (detailed version).
void Allocator::dumpInfoEx(void) const
{
#ifndef _NDEBUG
  DumpInfoEx(&mMemoryHandle);
#endif
}
